<template>
	<view class="background" :style="{'--width':width,'--height':height}">
		<view class="top" :style="{'--width':width,'--height':height}">
			<uni-icons type="back" size="30" class="back" @click="back"></uni-icons>
			<text class="text1">调剂报告下载</text>
		</view>

		<view class="position-relative" @click="exportPDF">
			<view class="sampleTips text-center u-font-26 position-absolute" style="border-radius: 25rpx;">样本预览</view>
			<image mode="aspectFill"
				src="https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/10/13/ef63c99166f2430d95d43e1147fda704.png"
				class="tu" :style="{'--width':width,'--height':height}"></image>
		</view>
		<view class="but-all w-100">
			<view class="flex align-center justify-center">
				<uni-icons type="heart-filled" size="18" color="#f7dd5e"></uni-icons>
				<text class="font-24">按预估和实际分数，生成两份《调剂报告》</text>
			</view>
			<view>
				<button class="but1" @click="duihuan">已购点我</button>
				<view class="but2" @click="hanldePay"><text class="text3"
						:style="{'--width':width,'--height':height}">购买</text><text class="text2">(￥{{much}})</text></view>
			</view>
		</view>
		<u-modal @confirm="goumai" show-cancel-button	 confirm-color="#ff7b08" v-model="show"  content="您已经购买过一份调剂报告了，可以在个人中心进行下载；确定要再另外购买一份吗？"></u-modal>
	</view>
</template>

<script>
	import {
		jiage,
		zhifu,
		isBuyAdjustReportSchool
	} from "@/api/toolbox.js"
	export default {
		data() {
			return {
				show: false,
				width: 0,
				height: 0,
				much: "999",
				list: {
					"goodsId": 36,
					"goodsType": "13",
					"payWay": "1",
					"payProduct": "1",
					"attach": {
						"schoolCode": "",
						"collegeCode": "",
						"majorCode": ""
					}
				},
			}
		},
		onLoad() {
			let a = uni.getWindowInfo()
			this.width = a.screenWidth
			this.height = a.screenHeight
			jiage().then((res) => {
				this.much = res.data.price
			})
			/*#ifdef APP-PLUS*/
			console.log('APP端')
			this.paylist.payProduct = "2"
			/*#endif*/
		},
		methods: {
			getData() {
				isBuyAdjustReportSchool().then(res => {
					if (res.data > 0) {
						this.show = true;
					} else {
						this.goumai();
					}
				})
			},
			exportPDF() {
				uni.showLoading({
					title: "加载中...",
					mask: true
				});
				//  #ifdef H5
				window.open(
					"https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/10/10/197646ff8fa14f2ebd305c1c4d7532d6.pdf"
				)
				// #endif
				// 微信下载文件需要在微信公众平台>开发>开发管理>服务器域名>downloadFile合法域名>配置白名单域名
				// #ifdef MP-WEIXIN
				uni.downloadFile({
					url: "https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/10/10/197646ff8fa14f2ebd305c1c4d7532d6.pdf",
					success: res => {
						if (res.statusCode === 200) {
							uni.hideLoading();
							// 预览pdf文件
							uni.openDocument({
								filePath: res.tempFilePath,
								showMenu: true, // 右上角菜单，可以进行分享保存pdf
								success: function(file) {
									console.log("file-success", file)
								}
							})
						}
					}
				})
				// #endif

				// #ifdef APP-PLUS
				uni.downloadFile({
					url: 'https://aihelp.oss-cn-hangzhou.aliyuncs.com/public/base/2023/10/10/197646ff8fa14f2ebd305c1c4d7532d6.pdf',
					success: function(res) {
						uni.hideLoading();
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							showMenu: true,
							success: function(res) {
								console.log('打开文档成功');
							}
						});
					}
				});
				// #endif
			},
			back() {
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				prevPage.$vm.flag = 1
				uni.navigateBack();
			},
			duihuan() {
				uni.navigateTo({
					url: "duihuan"
				})
			},
			hanldePay() {
				this.getData();
			},
			goumai() {
				zhifu(this.list).then((res) => {
					console.log('res: ', res);
					let b = res.data.wechatPayResponse
					uni.requestPayment({
						appid: b.appid,
						provider: 'wxpay',
						timeStamp: b.timeStamp,
						nonceStr: b.noncestr,
						package: b.packageStr,
						signType: 'RSA',
						paySign: b.sign,
						success: function() {
							uni.navigateTo({
								url: "xinxi?value=1&&payOrderId=" + res.data.payOrderId
							})
						},
						fail: function(err) {
							console.log('fail:' + JSON.stringify(err));

						}
					});
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.background {
		background-color: #f0f0f0;
		width: calc(var(--width)*1px);
		height: calc(var(--height)/1000*940*1px);
	}

	.back {
		margin-left: calc(var(--width)/1000*10*1px);
	}

	.text1 {
		position: absolute;
		margin-left: calc(var(--width)/1000*30*1px);
		margin-top: calc(var(--height)/1000*3*1px);
		font-weight: bold;
	}

	.top {
		width: calc(var(--width)*1px);
		height: calc(var(--height)/1000*50*1px);
		background-color: white;
		margin-top: calc(var(--height)/1000*60*1px);
	}

	.tu {
		width: calc(var(--width)/1000*910*1px);
		height: calc(var(--height)/1000*700*1px);
		margin-left: calc(var(--width)/1000*40*1px);
		margin-top: calc(var(--height)/1000*30*1px);
		background-color: #FFFFFF;
	}

	.but1 {
		position: absolute;

		font-size: 16px;
		background-color: #72819A;

		width: calc(var(--width)/1000*350*1px);
		height: calc(var(--height)/1000*60*1px);
		margin-left: calc(var(--width)/1000*161*1px);
		margin-top: calc(var(--height)/1000*20*1px);
		border-top-left-radius: calc(var(--height)/1000*60/2*1px);
		border-bottom-left-radius: calc(var(--height)/1000*50/2*1px);
		line-height: calc(var(--height)/1000*60*1px);
	}

	.but2 {
		position: absolute;

		font-size: 16px;
		background-color: #FED534;

		width: calc(var(--width)/1000*350*1px);
		height: calc(var(--height)/1000*60*1px);
		margin-left: calc(var(--width)/1000*509*1px);
		margin-top: calc(var(--height)/1000*20*1px);

		border-top-right-radius: calc(var(--height)/1000*60/2*1px);
		border-bottom-right-radius: calc(var(--height)/1000*50/2*1px);
	}

	.text2 {
		position: absolute;
		margin-top: calc(var(--height)/1000*15*1px);
		margin-left: 55px;
		color: #ff7b08;

	}

	.but-all {
		position: fixed;
		bottom: 180rpx;
	}

	.text3 {
		position: absolute;
		margin-top: calc(var(--height)/1000*15*1px);
		margin-left: 20px;
	}

	.sampleTips {
		background: #333333;
		color: #FED534;
		left: 50rpx;
		top: 35rpx;
		left: calc(var(--width)/1000*50*1px);
		top: calc(var(--height)/1000*35*1px);
		width: 140rpx;
		height: 50rpx;
		line-height: 50rpx;
	}
</style>